<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="username"></div>
    <button class="button" onclick="handleLogin()">登录</button>
</body>
<script src="../jquery-3.6.0.min.js"></script>
<script>

    let ajax;

    import("../06ajax/02request.js").then(res => {
        ajax = res.ajax;
    });

    function doInit() {
        let jsonStr = localStorage.getItem("user");
        console.log(jsonStr);
        if (null != jsonStr) {
            let user = JSON.parse(jsonStr);
            console.log("user = ",user);
            $(".username").text(user.name);
        }
    }

    // $(".button").on("click",);


    function handleLogin() {
        ajax($,"/stuHtml/01/05jquery/07login/user.json").then(res => {
            localStorage.setItem("user",JSON.stringify(res.result_data));
            doInit();
        });
    }

    doInit();
</script>
</html>